<template>
	<view class="container">
		<view class="text-area">
			<!-- <text class="title">{{title}}</text> -->
		</view>
		<view class="text-nitice">
			<text class="nitice">{{notice}}</text>
		</view>
		<uni-section title="尊敬的用户,请登录" type="line">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms  >
					<uni-forms-item label="手机号" required>
						<uni-easyinput   v-model="userName" placeholder="手机号" />
					</uni-forms-item>
					<uni-forms-item label="密码" required>
						<uni-easyinput v-model="pwd" type="password"  placeholder="请输入密码" />
					</uni-forms-item>
			
				</uni-forms>
				
			</view>
		</uni-section>
	
	<button type="primary"  @click="login()">登录</button>
						
	<button type="default"  @click="reg()">注册</button>
							
	
	
		
	</view>
	
	<!-- <view class="content nvue-page-root">
		<form >
	
			<view class="text-area">
				<text class="title">{{title}}</text>
			</view>
			<view class="text-nitice">
				<text class="nitice">{{notice}}</text>
			</view>
			<uni-section title="基础信息" type="line">
				<view class="uni-padding-wrap uni-common-mt">
					<view class="uni-form-item uni-column">
						<view class="title"></view>
						<view class="uni-input-wrapper">
							<input class="uni-input" v-model="userName" type="number" focus maxlength="11" placeholder="手机号" />
						</view>
					</view>
				
					<view class="uni-form-item uni-column">
						<view class="title"></view>
						<view class="uni-input-wrapper">
							<input class="uni-input" v-model="pwd" placeholder="请输入密码" :password="showPassword" />
						<text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword">&#xe568;</text>
						</view>
					</view>
					<view class="uni-form-item uni-column ">
						
						
							<button type="primary"  @click="login()">登录</button>
					
							<button type="default"  @click="reg()">注册</button>
						
							
				
						
					</view>
				
				
				</view>
			</uni-section>
			
		</form>
	</view> -->
</template>

<script>
	import constant from '@/store/constant.js'
	const baseUrl=constant.baseUrl;
	export default {
		data() {
			return {
				title: '尊敬的用户,请登录',
				showPassword: true,
				src: '../../../static/eye-1.png',
				userName:"",
				pwd:"",
				notice:"",
			}
		},
		onLoad() {
			console.log("init")
		},
		methods: {
			changePassword: function() {
                this.showPassword = !this.showPassword;
            },
			login:function(){
				this.$data.notice="";
				if(this.$data.userName.length!=11){
					this.$data.notice="手机号格式不正确";
					return false;
				}
				if(this.$data.pwd.length==0){
					this.$data.notice="密码不可以为空";
					return false;
				}
				uni.request({
					// url:"http://192.168.1.4:9000/api/user/login",
					url:baseUrl+"/api/user/login",
					method:"POST",
					data:{userName:this.$data.userName,pwd:this.$data.pwd},
					success: (res) => {
						console.log(res);
					        if(res.data.code==0){
					        
								console.log(JSON.stringify(res.data.result))
					        	uni.setStorageSync('authInfo', JSON.stringify(res.data.result));
								uni.setStorageSync('token', res.data.result.token);
								constant.authInfo=res.data.result;
					        	uni.redirectTo({
					        		url:"/pages/home/home"
					        	})
					        	
					        }else{
					        	this.$data.notice=res.data.message;
					        }
					},
					fail:function(err){
						console.log(err)
					}
				})
				console.log(this.$data.userName)
				console.log(this.$data.pwd);
			},
			reg:function(){
				uni.redirectTo({
					url:"/pages/register/register"
				})
			},
		}
	}
</script>

<style scoped>
	.example {
		padding: 15px;
		background-color: #fff;
	}
	
	.segmented-control {
		margin-bottom: 15px;
	}
	
	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}
	
	.form-item {
		display: flex;
		align-items: center;
	}
	
	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
	.text-area {
		display: flex;
		justify-content: center;
	}
	
	.title {
		/* font-size: 36rpx; */
		color: #8f8f94;
	}
</style>
